<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS对象JSON</title>
</head>
<body>
    
</body>
<script>
    //js中的自定义对象,属性间用，分割，类似c++结构体
    var duix = {
        name : "AGE",
        age : 16,
        gender : "男",
        eat : function(){
            alert("我错过了");
        }
    }

    console.log(duix.name);
    // console.log(duix.eat());

    //JSON数据格式key-value，用双引号
    // {
    //     "name" : "TOM",
    //     "age" : 20,
    //     "gender" :"man",
    //     "addr:["北京","上海","成都"]",
    // }

    //定义JSON
    var json = '{"name": "TOM","age" : 20,"gender" : "man","addr":["北京","上海","成都"]}';

    //JSON字符串转JSON对象
    var json_show = JSON.parse(json);
    console.log(json_show);

    //JSON对象转JSON字符串
    var jsonStr = JSON.stringify(json_show);
    console.log(jsonStr);

</script>
</html>